package com.gdu.video;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Set;

import android.R.bool;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.media.AudioManager;
import android.media.AudioTrack;
import android.util.Log;
import android.view.Surface;

public class RealVideo {
	final String TAG = "VideoInterface";
	WFRender mRender;
	RealvideoCallback mCallback = null;
	
	public RealVideo(WFRender render, RealvideoCallback callback) {
		mRender = render;
		
		mCallback = callback;
	}

	private native int openStream(String uriPath,RealVideo object);

	private native int closeStream();

	private native int startScope(String uriPath, boolean audioOn);
	
	public int OpenStream(String uriPath) {
		if (connectState == 0) {
			return openStream(uriPath,this);
		} else {
			return -1;
		}
	}
	
	public int CloseStream() {
		return closeStream();
	}
	
	public void changeFilter()
	{
		mRender.setFilter(1);
	}

	
	int connectState = 0;
	public void OnConnectionStateChanged(int connectOK, int videoWidth, int videoHeight) {
		if (connectOK > 0) {
			connectState = 1;
			Log.v(TAG, "connect OK");
			
			mRender.update(videoWidth, videoHeight);
		} else {
			connectState = -1;
			Log.v(TAG, "connect Error");
		}
	}
	
	
	public void OnConnectionStop() {
		connectState = 0;
	}

	public void OnParamArrived(byte[] param, int length) {
		if (mCallback != null) {
			mCallback.OnParamArrived(param);
		}
	}
	
	public boolean OnFrameDataArrived(int width, int height, byte[] yData, byte[] uData, byte[] vData) {
		boolean frameDataChanged = false;
		if (mCallback != null) {
			frameDataChanged = mCallback.OnFrameDataArrived(width, height, yData, uData, vData);
		}
		Log.e("video","reder yuv");
		mRender.update(yData, uData, vData);
		return frameDataChanged;
	}
	
	  //拍照的照片数据，以RGB数组传递
    public void OnSlapDataArrived(int width, int height, byte[] rgbData,
                                  int length) {
        Bitmap _image = Bitmap.createBitmap(width, height, Config.RGB_565);
        _image.copyPixelsFromBuffer(ByteBuffer.wrap(rgbData));
        Log.e("video","get bmp");
        
    }

}
